<template>
  <div class="parent">
    <echartsDom v-if="isShowEcharts" style="width: 100%; height: 100%" :width="'100%'" :height="'100%'" :option="option" :type="type" />
    <div v-else>
      <px-empty :image-size="50" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, ref } from "vue";
import echartsDom from "./echartsDom.vue";
import { queryRecycleRateIndicator } from "@/api/waterKanban";
const props = defineProps({
  width: {
    type: String,
    default: ""
  },
  height: {
    type: String,
    default: ""
  },
  color: {
    type: String,
    default: "#3B82F6"
  },
  type: {
    type: String,
    default: ""
  }
});
const isShowEcharts = ref(false);
const state = reactive({
  option: {}
});
const { option } = toRefs(state);

const getoptions = () => {
  queryRecycleRateIndicator({ dictKey: "RI01", day: 7 }).then((response: any) => {
    console.log(response);
    isShowEcharts.value = true;
    option.value = {
      backgroundColor: props.type == "dark" ? "#001e3b" : "",
      color: ["#5792F3 ", "#2C29FF", "#28D892", "#FF5639"],
      grid: {
        left: "30px",
        top: "40px",
        right: "0px",
        bottom: "10px",
        containLabel: true
      },
      legend: {},
      tooltip: {
        confine: true
      },
      xAxis: {
        type: "category",
        boundarGap: false,
        data: response.xaxis
      },
      yAxis: {
        name: "总回收率（%）",
        type: "value"
      },
      series: [
        {
          data: response.panelList[0].details.map(item => (item.value ? item.value * 100 : 0)),
          type: "bar",
          name: "总回收率（%）",
          stack: "total",
          barWidth: "25px",
          emphasis: {
            focus: "series"
          }
        }
      ]
    };
  });
};
getoptions();
</script>

<style scoped lang="scss">
.parent {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>
